#!/usr/bin/env python
#-*- coding: utf-8 -*-
'''=========================
@Time : 2020/7/19 20:20
@Coder: xh
@IDE  : PyCharm
========================='''
import requests
import pandas as pd
import json


class GetWeather(object):
    def __init__(self,kind,city):
        self.kind = kind
        self.city = city


    def get_weather_info(self):
        city_data = pd.read_json('weather_api/city.json')
        city_dict = city_data.set_index('cityZh')['id'].to_dict()
        input_city = self.city
        city_id = city_dict['{}'.format(input_city)]
        if self.kind == 0:
            url = 'https://yiketianqi.com/api?version=v62&appid=75933893&appsecret=HDgpSi7e&cityid={}'.format(city_id)
            response = requests.get(url)
            weather_info = json.loads(response.text)
            return weather_info
        elif self.kind == 1:
            url = 'https://yiketianqi.com/api?version=v9&appid=75933893&appsecret=HDgpSi7e&cityid={}'.format(city_id)
            response = requests.get(url)
            weather_info = json.loads(response.text)
            data = weather_info['data']
            return data
if __name__ == '__main__':
    w = GetWeather(1,'静宁')
    data =w.get_weather_info()
    print(data)

